//
//  GiveUpReserveViewController.m
//  Manager
//
//  Created by 彭凯敏 on 15/8/17.
//  Copyright (c) 2015年 52xiaoluo. All rights reserved.
//

#import "GiveUpReserveViewController.h"
#import "UnsignedViewController.h"
@interface GiveUpReserveViewController ()
@property (weak, nonatomic) IBOutlet UITextView *textView;
- (IBAction)clickGiveup:(UIButton *)sender;
//放弃原因

@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *BtnArray;
- (IBAction)clickBtn:(UIButton *)sender;

@end

@implementation GiveUpReserveViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
     [self baseCtlSetTitle:@"用户放弃订房"];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(requestSuccess:) name:CMD_ViewRoom_ReserveRoomReq object:nil];

    [self resetUI];
}
- (void)resetUI
{
    NSArray *array = @[@"价格不合适",@"房源不合适",@"室友性别原因",@"交通不顺利",@"不着急租房",@"希望短租",];
    
    
    for (NSInteger i = 0; i<_BtnArray.count; i++) {
        UIButton *btn = _BtnArray[i];
        [btn setTitle:array[i] forState:UIControlStateNormal];
        
    }
    
    
    
}
- (void)giveupRoomReq
{
    ReserveRoomReqBuilder *builder = [[ReserveRoomReqBuilder alloc]init];
    [builder setIsReserve:NO];
    
    [builder setViewOrderId:_orderInfo.id];
    SignInfoBuilder *infoBuilder = [[SignInfoBuilder alloc]init];
    RoomInfo *room = [[RoomInfo alloc]init];
    room = _orderInfo.viewRooms[0];
    
    [infoBuilder setRoomId:room.roomId];
    
    [builder setSignInfo: infoBuilder.build];
    
    [builder setUnSignRemark:_textView.text];
    
    [[ViewRoomLogic shareInstance]reserveRoomReqWithBuild:builder.build];
}
- (void)requestSuccess:(NSNotification *)noti
{
    dispatch_async(dispatch_get_main_queue(), ^{
        if ([noti.name isEqualToString:CMD_ViewRoom_ReserveRoomReq]) {
            HUDRemove;
            if ([noti.object isKindOfClass:[ErrorModel class]])
            {
                ErrorModel *model = noti.object;
                [UIViewCategory FailShowWith:model];
                
            }
            else
            {
                
                [self.navigationController pushViewController:[[UnsignedViewController alloc] init] animated:YES];
                
                NSArray *array = self.navigationController.viewControllers;
                self.navigationController.viewControllers = @[array[0],array[3]];
                
//                [[NSNotificationCenter defaultCenter]postNotificationName:RecordPushVC object:[[UnsignedViewController alloc] init]];
//                
//               [self.navigationController popToRootViewControllerAnimated:NO];
                
                SuccessShow(@"放弃看房成功");
            }
            
        }
    });
    
    
    
}

- (IBAction)clickGiveup:(UIButton *)sender {
    
    HUDShow(nil);
    [self giveupRoomReq];
 
    
}
- (IBAction)clickBtn:(UIButton *)sender
{
 
    _textView.text = [NSString stringWithFormat:@"%@%@，",_textView.text,sender.titleLabel.text];
    
}
@end
